package com.yanqu.road.web.timer;

import com.yanqu.road.api.test.JobManager;
import com.yanqu.road.api.test.TestJob;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.List;
import java.util.Map;

public class TestJobTask extends GeneralTask {

    @Override
    public void doRun() {

        for (Map.Entry<Long, TestJob> entry : JobManager.getJobMap().entrySet()) {
            TestJob job = entry.getValue();
            job.keep();
        }

        for (Map.Entry<Long, List<YanQuMessage>> entry : JobManager.getJobMessageMap().entrySet()) {
            TestJob job = JobManager.getJobById(entry.getKey());
            if(job != null){
                List<YanQuMessage> list = entry.getValue();
                for (int i = 0; i < list.size(); i++) {
                    job.write(list.get(i));
                }
            }
        }

    }
}
